package com.lantosec.hmrp.modules.notify.controller.app;


import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.core.mvc.BaseController;
import com.lantosec.hmrp.modules.notify.entity.NotifyInfo;
import com.lantosec.hmrp.modules.notify.entity.NotifyRecipient;
import com.lantosec.hmrp.modules.notify.service.INotifyInfoService;
import com.lantosec.hmrp.modules.notify.vo.NotifyInfoVO;
import com.lantosec.hmrp.modules.notify.vo.NotifyTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 通知 控制器
 *
 * @author AutoCode
 * @since 2020-05-22
 */
@Api(value = "通知控制器APP端", tags = "通知控制器APP端")
@RestController
@RequestMapping("/notify/app/info")
@Log4j2
public class NotifyInfoAppController extends BaseController {
    @Autowired
    private INotifyInfoService service;

    @GetMapping("getAll")
    @ApiOperation(value = "查询分类列表")
    public Result<List<NotifyTypeVO>> getAll(){
        List<NotifyTypeVO> notifyTypeVOList = service.getAll();
        return Result.ok(notifyTypeVOList);
    }

    @GetMapping("get/{notifyTypeId}")
    @ApiOperation(value = "查询已读未读列表")
    public Result<List<NotifyInfoVO>> get(@ApiParam(value = "类型id") @PathVariable(name = "notifyTypeId",required = false) String notifyTypeId){
        List<NotifyInfoVO> notifyInfoVOList = service.get(notifyTypeId);
        return Result.ok(notifyInfoVOList);
    }

    @PutMapping("updateRead")
    @ControllerLog(name = "更新为已读", type = LogType.update)
    @ApiOperation(value = "更新为已读")
    public Result<Void> updateRead(@ApiParam(value = "通知VO对象", required = true) @RequestBody List<NotifyRecipient> notifyRecipientList){
        service.updateRead(notifyRecipientList);
        return Result.ok();
    }

    @PutMapping("updateDelete")
    @ControllerLog(name = "更新为删除", type = LogType.update)
    @ApiOperation(value = "更新为删除")
    public Result<Void> updateDelete(@ApiParam(value = "通知VO对象", required = true) @RequestBody List<NotifyRecipient> notifyRecipientList){
        service.updateDelete(notifyRecipientList);
        return Result.ok();
    }

    @GetMapping("getPublicRead")
    @ApiOperation(value = "登录显示系统公告")
    public Result<List<NotifyInfoVO>> getPublicRead(){
        List<NotifyInfoVO> notifyInfoVOList = service.getPublicRead();
        return Result.ok(notifyInfoVOList);
    }

    @GetMapping("getPublicReadAll")
    @ApiOperation(value = "查询系统公告")
    public Result<List<NotifyInfoVO>> getPublicReadAll(){
        List<NotifyInfoVO> notifyInfoVOList = service.getPublicReadAll();
        return Result.ok(notifyInfoVOList);
    }

}
